﻿Imports System.Data.SqlClient

Public Class frmSlipsManagement

    Sub FillSlips()
        Try
            Me.Cursor = Cursors.WaitCursor

            Dim cmd As New SqlCommand("Select * From Slips Where InsuranceCompany Like N'%" & Me.CombInsurComp.Text.Trim & "%' and " & _
                                      "LineOfBuiness Like N'%" & Me.CombInsurClasses.Text.Trim & "%' and C1 Like N'%" & Me.txtInsured.Text.Trim & "%'", cnn)
            Dim Reader As SqlDataReader

            Me.GridSlips.Rows.Clear()

            cnn.Open()
            Reader = cmd.ExecuteReader
            While (Reader.Read)
                Me.GridSlips.Rows.Add(New String() {Reader.Item("SNo"), Reader.Item("SlipNo"), Reader.Item("Status"), Reader.Item("InsuranceCompany"), Reader.Item("C1"), _
                                                    Reader.Item("LineOfBuiness"), Reader.Item("UserName"), _
                                                    CDate(Reader.Item("TransDate")).ToString("yyyy/MM/dd")})
            End While
            cnn.Close()

            'Count no. of results
            Me.lblResult.Text = "Results found: " & Me.GridSlips.Rows.Count

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub frmSlipsManagement_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
    End Sub

    Private Sub ContractorsAllRisksCARToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContractorsAllRisksCARToolStripMenuItem.Click
        Dim a As New frmSlipCAR
        a.LineOfBuiness = "Contractor's All Risks"
        a.Abbreviation = "CAR"
        a.ShowDialog()
    End Sub

    Private Sub FidelityGuaranteeInsuranceFGIToolStripMenuItem_Click_1(sender As System.Object, e As System.EventArgs) Handles FidelityGuaranteeInsuranceFGIToolStripMenuItem.Click
        Dim a As New frmSlipFG
        a.LineOfBuiness = "Fidelity Guarantee"
        a.Abbreviation = "FGI"
        a.Show()
    End Sub

    Private Sub FireAndAlliedPerilsFAPToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FireAndAlliedPerilsFAPToolStripMenuItem.Click
        Dim a As New frmSlipFAP
        a.LineOfBuiness = "Fire and Allied Perils"
        a.Abbreviation = "FAP"
        a.ShowDialog()
    End Sub

    Private Sub InlandTransitAllRisksInsuranceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InlandTransitAllRisksInsuranceToolStripMenuItem.Click
        Dim a As New frmITAR
        a.LineOfBuiness = "Inland Transit All Risks"
        a.Abbreviation = "ITAR"
        a.ShowDialog()
    End Sub

    Private Sub MarineCargoInsuranceMACToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MarineCargoInsuranceMACToolStripMenuItem.Click
        Dim a As New frmSlipMAC
        a.LineOfBuiness = "Marine Cargo"
        a.Abbreviation = "MAC"
        a.ShowDialog()
    End Sub

    Private Sub AllRisksInsurancePARToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AllRisksInsurancePARToolStripMenuItem.Click
        Dim a As New frmSlipPAR
        a.LineOfBuiness = "Property All Risks"
        a.Abbreviation = "PAR"
        a.ShowDialog()
    End Sub

    Private Sub ProductLiabilityPPLToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductLiabilityPPLToolStripMenuItem.Click
        Dim a As New frmSlipPPL
        a.LineOfBuiness = "Public Liability"
        a.Abbreviation = "PLL"
        a.ShowDialog()
    End Sub

    Private Sub ProfessionalIndemnityPULToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProfessionalIndemnityPULToolStripMenuItem.Click
        Dim a As New frmSlipPUL
        a.LineOfBuiness = "Professional Indemnity"
        a.Abbreviation = "PII"
        a.ShowDialog()
    End Sub

    Private Sub WorkmansCompensationWCAToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WorkmansCompensationWCAToolStripMenuItem.Click
        Dim a As New frmSlipWCA
        a.LineOfBuiness = "Workman's Compensation"
        a.Abbreviation = "WCA"
        a.ShowDialog()
    End Sub

    Private Sub DeteriorationOfStockDOSToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeteriorationOfStockDOSToolStripMenuItem.Click
        Dim a As New frmSlipMBD
        a.LineOfBuiness = "Deterioration of Stock"
        a.Abbreviation = "DOS"
        a.ShowDialog()
    End Sub

    Private Sub MoneyMONToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MoneyMONToolStripMenuItem.Click
        Dim a As New frmSlipMON
        a.LineOfBuiness = "Money"
        a.Abbreviation = "MON"
        a.ShowDialog()
    End Sub

    Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
        Me.CombInsurComp.Text = ""
        Me.CombInsurClasses.Text = ""
        Me.txtInsured.Clear()
    End Sub

    Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
        FillSlips()
    End Sub

    Private Sub ToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripMenuItem1.Click
        Dim a As New frmSlipMACO
        a.LineOfBuiness = "Marine Cargo All Risks - Open Cover"
        a.Abbreviation = "MACO"
        a.ShowDialog()
    End Sub

    Private Sub GridSlips_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GridSlips.CellClick
        If e.ColumnIndex = Me.DGColEdit.Index Then
            If Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Contractor's All Risks" Then
                Dim a As New frmSlipCAR
                a.LineOfBuiness = "Contractor's All Risks"
                a.Abbreviation = "CAR"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Fidelity Guarantee" Then
                Dim a As New frmSlipFG
                a.LineOfBuiness = "Fidelity Guarantee"
                a.Abbreviation = "FGI"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Fire and Allied Perils" Then
                Dim a As New frmSlipFAP
                a.LineOfBuiness = "Fire and Allied Perils"
                a.Abbreviation = "FAP"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Inland Transit All Risks" Then
                Dim a As New frmITAR
                a.LineOfBuiness = "Inland Transit All Risks"
                a.Abbreviation = "ITAR"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Marine Cargo" Then
                Dim a As New frmSlipMAC
                a.LineOfBuiness = "Marine Cargo"
                a.Abbreviation = "MAC"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Property All Risks" Then
                Dim a As New frmSlipPAR
                a.LineOfBuiness = "Property All Risks"
                a.Abbreviation = "PAR"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Public Liability" Then
                Dim a As New frmSlipPPL
                a.LineOfBuiness = "Public Liability"
                a.Abbreviation = "PLL"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Professional Indemnity" Then
                Dim a As New frmSlipPUL
                a.LineOfBuiness = "Professional Indemnity"
                a.Abbreviation = "PII"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Workman's Compensation" Then
                Dim a As New frmSlipWCA
                a.LineOfBuiness = "Workman's Compensation"
                a.Abbreviation = "WCA"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Deterioration of Stock" Then
                Dim a As New frmSlipMBD
                a.LineOfBuiness = "Deterioration of Stock"
                a.Abbreviation = "DOS"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Money" Then
                Dim a As New frmSlipMON
                a.LineOfBuiness = "Money"
                a.Abbreviation = "MON"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            ElseIf Me.GridSlips.CurrentRow.Cells(Me.DGColLineOfBusiness.Index).Value = "Marine Cargo All Risks - Open Cover" Then
                Dim a As New frmSlipMACO
                a.LineOfBuiness = "Marine Cargo All Risks - Open Cover"
                a.Abbreviation = "MACO"
                a.EditSNo = CInt(Me.GridSlips.CurrentRow.Cells(Me.DGColSNo.Index).Value)
                a.EditSlipNo = Me.GridSlips.CurrentRow.Cells(Me.DGColDocSNo.Index).Value
                a.EditMode = True
                a.ShowDialog()

            End If
        End If
    End Sub
End Class